package net.sansi.v3correctserver.entity.space;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import net.sansi.v3correctserver.constenum.DateConst;
import net.sansi.v3correctserver.service.space.ProjectSpace;
import net.sansi.v3correctserver.util.SpaceUtil;

import java.nio.file.Path;
import java.time.LocalDateTime;

/**
 * Created by Fang
 * create time : 2025/1/22
 * IDE : IntelliJ IDEA
 * <p>
 * 项目空间配置
 */

@Getter
@Setter
@ApiModel(description = "项目空间配置")
public class ProjectSpaceCnf {

    @ApiModelProperty(value = "项目id")
    private String id;

    @ApiModelProperty(value = "项目名称")
    private String name;

    @ApiModelProperty(value = "项目描述")
    private String description;

    @ApiModelProperty(value = "项目所在目录")
    private String path;

    @ApiModelProperty(value = "项目创建时间")
    @JsonFormat(pattern = DateConst.DATE_TIME_PATTERN)
    private LocalDateTime createTime;

    @ApiModelProperty(value = "项目更新时间")
    @JsonFormat(pattern = DateConst.DATE_TIME_PATTERN)
    private LocalDateTime updateTime;

    @ApiModelProperty(value = "文件夹是否存在")
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private Boolean exist = true;


    /**
     * 设置项目路径
     *
     * @param path 项目路径
     */
    public void setPath(Path path) {
        this.path = path.toAbsolutePath().toString();
    }

    public void setPath(String path) {
        this.path = path;
    }

    /**
     * 获取项目路径
     *
     * @return 项目路径
     */
    @JsonIgnore
    public Path getSpacePath() {
        return Path.of(path).normalize();
    }

    /**
     * 获取项目空间
     *
     * @return 项目空间
     */
    @JsonIgnore
    public SpaceUtil getSpaceUtil() {
        return new SpaceUtil(getSpacePath());
    }

    /**
     * 获取项目空间
     *
     * @return 项目空间
     */
    @JsonIgnore
    public ProjectSpace getProjectSpace() {
        return new ProjectSpace(this);
    }
}
